package com.zhang;

import com.zhang.list.List;
import com.zhang.list.TwoLinkedList;

/**
 * 双端队列（double ended queue)
 */
public class Deque<E> {
    private List<E> list = new TwoLinkedList<>();

    public int size() {
        return list.size();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    public void clear() {
        list.clear();
    }

    // 队尾入队
    public void enQueueRear(E element) {
        list.add(element);
    }

    // 对头出队
    public E deQueueFront() {
        return list.remove(0);
    }

    // 对头入队
    public void enQueueFront(E element) {
        list.add(0, element);
    }

    // 队尾出队
    public E deQueueRear() {
        return list.remove(size() - 1);
    }

    public E front() {
        return list.get(0);
    }

    public E rear() {
        return list.get(size() - 1);
    }
}
